package com.ruoyi.basic.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;

import com.ruoyi.basic.domain.AtbQueryNavigation;

import com.ruoyi.common.filter.ID;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.objectPic.domain.AtbObjectPic;
import com.ruoyi.objectPic.mapper.AtbObjectPicMapper;
import com.ruoyi.officeInfo.domain.AtbOfficeInfo;
import com.ruoyi.officeInfo.domain.AtbOfficeInfoDto;
import com.ruoyi.officeInfo.mapper.AtbOfficeInfoMapper;
import com.ruoyi.realEstate.domain.AtbRealEstate;
import com.ruoyi.realEstate.domain.AtbRealEstateDto;
import com.ruoyi.realEstate.mapper.AtbRealEstateMapper;
import com.ruoyi.shopInfo.domain.AtbShopInfo;
import com.ruoyi.shopInfo.domain.AtbShopInfoDto;
import com.ruoyi.shopInfo.mapper.AtbShopInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basic.mapper.AtbShapMapper;
import com.ruoyi.basic.domain.AtbShap;
import com.ruoyi.basic.service.IAtbShapService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 地产商业基本信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-14
 */
@Service
public class AtbShapServiceImpl implements IAtbShapService 
{
    @Autowired
    private AtbShapMapper atbShapMapper;


    @Autowired
    private AtbShopInfoMapper atbShopInfoMapper;

    @Autowired
    private AtbOfficeInfoMapper atbOfficeInfoMapper;

    @Autowired
    private AtbRealEstateMapper atbRealEstateMapper;


    @Autowired
    private AtbObjectPicMapper atbObjectPicMapper;




    /**
     * 查询地产商业基本信息
     * 
     * @param id 地产商业基本信息主键
     * @return 地产商业基本信息
     */
    @Override
    public AtbShap selectAtbShapById(Long id)
    {


        return atbShapMapper.selectAtbShapById(id);
    }

    /**
     * 查询地产商业基本信息列表
     * 
     * @param atbShap 地产商业基本信息
     * @return 地产商业基本信息
     */
    @Override
    public List<AtbShap> selectAtbShapList(AtbShap atbShap)
    {
        return atbShapMapper.selectAtbShapList(atbShap);
    }

    /**
     * 新增地产商业基本信息
     * 
     * @param atbShap 地产商业基本信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertAtbShap(AtbShap atbShap)
    {
        //雪花算法生成主键ID
        ID id = new ID();
        atbShap.setId(id.getId());


        String[] split = atbShap.getMovies().split(",");
        for (String s : split) {

            //图片添加
            AtbObjectPic atbObjectPic = new AtbObjectPic();
            atbObjectPic.setUrl(s);
            atbObjectPic.setObjectId(atbShap.getId());
            atbObjectPicMapper.insertAtbObjectPic(atbObjectPic);
        }


        atbShap.setCreateTime(DateUtils.getNowDate());
        return atbShapMapper.insertAtbShap(atbShap);
    }

    /**
     * 修改地产商业基本信息
     * 
     * @param atbShap 地产商业基本信息
     * @return 结果
     */
    @Override
    public int updateAtbShap(AtbShap atbShap)
    {
        return atbShapMapper.updateAtbShap(atbShap);
    }

    /**
     * 批量删除地产商业基本信息
     * 
     * @param ids 需要删除的地产商业基本信息主键
     * @return 结果
     */
    @Override
    public int deleteAtbShapByIds(Long[] ids)
    {
        return atbShapMapper.deleteAtbShapByIds(ids);
    }

    /**
     * 删除地产商业基本信息信息
     * 
     * @param id 地产商业基本信息主键
     * @return 结果
     */
    @Override
    public int deleteAtbShapById(Long id)
    {



        //根据id查看图片图片集合

        List<AtbObjectPic> atbObjectPicList  = atbObjectPicMapper.selectList(id);

        for (AtbObjectPic atbObjectPic : atbObjectPicList) {
            atbObjectPicMapper.deleteAtbObjectPicById(atbObjectPic.getId());
        }
        return atbShapMapper.deleteAtbShapById(id);
    }

    @Override
    public List<AtbQueryNavigation> atbQueryNavigationList() {
        return atbShapMapper.atbQueryNavigationList();
    }

    @Override
    public Object getSelectTypeIdById(Long id) {
//        查询基本信息
        AtbShap atbShap = atbShapMapper.selectAtbShapById(id);

        if(atbShap.getSelectType() ==13 || atbShap.getSelectType()==14){
            //查询商铺信息
            AtbShopInfo atbShopInfo = atbShopInfoMapper.selectAtbShopInfoById(id);
            AtbShopInfoDto atbShopInfoDto = BeanUtil.toBean(atbShopInfo, AtbShopInfoDto.class);
            atbShopInfoDto.setId(atbShopInfo.getId());
            atbShopInfoDto.setShopMessageInfo(atbShopInfo.getShopMessageInfo());
            atbShopInfoDto.setShopSell(atbShopInfo.getShopSell());
            atbShopInfoDto.setShopPay(atbShopInfo.getShopPay());
            atbShopInfoDto.setShopStatus(atbShopInfo.getShopStatus());
            atbShopInfoDto.setShopTypeId(atbShopInfo.getShopTypeId());
            atbShopInfoDto.setFloor(atbShopInfo.getFloor());
            atbShopInfoDto.setTenancyTerm(atbShopInfo.getTenancyTerm());
            atbShopInfoDto.setPassengerFlow(atbShopInfo.getPassengerFlow());

            atbShopInfoDto.setSelectType(atbShap.getSelectType());
            atbShopInfoDto.setShopStatus(atbShap.getShopStatus());
            atbShopInfoDto.setShopMessage(atbShap.getShopMessage());
            atbShopInfoDto.setShopArea(atbShap.getShopArea());
            atbShopInfoDto.setShopDistance(atbShap.getShopDistance());
            atbShopInfoDto.setAddress(atbShap.getAddress());
            atbShopInfoDto.setAddressLatitude(atbShap.getAddressLatitude());
            atbShopInfoDto.setAddressLongitude(atbShap.getAddressLongitude());
            atbShopInfoDto.setCity1(atbShap.getCity1());
            atbShopInfoDto.setCity2(atbShap.getCity2());
            atbShopInfoDto.setCity3(atbShap.getCity3());
            atbShopInfoDto.setMovies(atbShap.getMovies());
            atbShopInfoDto.setSourceId(atbShap.getSourceId());
            atbShopInfoDto.setPrice(atbShap.getPrice());
            atbShopInfoDto.setIsExamine(atbShap.getIsExamine());
            atbShopInfoDto.setIsPutaway(atbShap.getIsPutaway());

            return atbShopInfoDto;

        }else if(atbShap.getSelectType() ==15 || atbShap.getSelectType()==16){
            //查询写字楼信息
            AtbOfficeInfo atbOfficeInfo = atbOfficeInfoMapper.selectAtbOfficeInfoById(id);


            AtbOfficeInfoDto atbOfficeInfoDto = BeanUtil.toBean(atbOfficeInfo, AtbOfficeInfoDto.class);
            atbOfficeInfoDto.setId(atbOfficeInfo.getId());
            atbOfficeInfoDto.setShopMessage(atbOfficeInfo.getOfficeBuildingInfo());
            atbOfficeInfoDto.setIsExamine(atbOfficeInfo.getIsExamine());
            atbOfficeInfoDto.setIsPutaway(atbOfficeInfo.getIsPutaway());
            atbOfficeInfoDto.setShopTypeId(atbOfficeInfo.getShopTypeId());
            atbOfficeInfoDto.setFloor(atbOfficeInfo.getFloor());
            atbOfficeInfoDto.setRegister(atbOfficeInfo.getRegister());
            atbOfficeInfoDto.setFitment(atbOfficeInfo.getFitment());
            atbOfficeInfoDto.setShopPay(atbOfficeInfo.getShopPay());
            atbOfficeInfoDto.setTenancyTerm(atbOfficeInfo.getTenancyTerm());
            atbOfficeInfoDto.setDistrictId(atbOfficeInfo.getDistrictId());



            atbOfficeInfoDto.setSelectType(atbShap.getSelectType());
            atbOfficeInfoDto.setShopStatus(atbShap.getShopStatus());
            atbOfficeInfoDto.setShopMessage(atbShap.getShopMessage());
            atbOfficeInfoDto.setShopArea(atbShap.getShopArea());
            atbOfficeInfoDto.setShopDistance(atbShap.getShopDistance());
            atbOfficeInfoDto.setAddress(atbShap.getAddress());
            atbOfficeInfoDto.setAddressLatitude(atbShap.getAddressLatitude());
            atbOfficeInfoDto.setAddressLongitude(atbShap.getAddressLongitude());
            atbOfficeInfoDto.setCity1(atbShap.getCity1());
            atbOfficeInfoDto.setCity2(atbShap.getCity2());
            atbOfficeInfoDto.setCity3(atbShap.getCity3());
            atbOfficeInfoDto.setMovies(atbShap.getMovies());
            atbOfficeInfoDto.setSourceId(atbShap.getSourceId());
            atbOfficeInfoDto.setPrice(atbShap.getPrice());
            atbOfficeInfoDto.setIsExamine(atbShap.getIsExamine());
            atbOfficeInfoDto.setIsPutaway(atbShap.getIsPutaway());
            return atbOfficeInfoDto;
        }

        //查询仓库
        AtbRealEstate atbRealEstate = atbRealEstateMapper.selectAtbRealEstateById(id);


        AtbRealEstateDto atbRealEstateDto = BeanUtil.toBean(atbRealEstate, AtbRealEstateDto.class);

        atbRealEstateDto.setId(atbRealEstate.getId());
        atbRealEstateDto.setIsExamine(atbRealEstate.getIsExamine());
        atbRealEstateDto.setIsPutaway(atbRealEstate.getIsPutaway());
        atbRealEstateDto.setRealType(atbRealEstate.getRealType());
        atbRealEstateDto.setRealType(atbRealEstate.getRealType());
        atbRealEstateDto.setEstateName(atbRealEstate.getEstateName());
        atbRealEstateDto.setEstateType(atbRealEstate.getEstateType());
        atbRealEstateDto.setLeaseCommencementDate(atbRealEstate.getLeaseCommencementDate());
        atbRealEstateDto.setLeaseWay(atbRealEstate.getLeaseWay());




        atbRealEstateDto.setSelectType(atbShap.getSelectType());
        atbRealEstateDto.setShopStatus(atbShap.getShopStatus());
        atbRealEstateDto.setShopMessage(atbShap.getShopMessage());
        atbRealEstateDto.setShopArea(atbShap.getShopArea());
        atbRealEstateDto.setShopDistance(atbShap.getShopDistance());
        atbRealEstateDto.setAddress(atbShap.getAddress());
        atbRealEstateDto.setAddressLatitude(atbShap.getAddressLatitude());
        atbRealEstateDto.setAddressLongitude(atbShap.getAddressLongitude());
        atbRealEstateDto.setCity1(atbShap.getCity1());
        atbRealEstateDto.setCity2(atbShap.getCity2());
        atbRealEstateDto.setCity3(atbShap.getCity3());
        atbRealEstateDto.setMovies(atbShap.getMovies());
        atbRealEstateDto.setSourceId(atbShap.getSourceId());
        atbRealEstateDto.setPrice(atbShap.getPrice());
        atbRealEstateDto.setIsExamine(atbShap.getIsExamine());
        atbRealEstateDto.setIsPutaway(atbShap.getIsPutaway());
        return atbRealEstateDto;

    }


}
